<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/***************************************************************************
 * 
 * Copyright (c) 2014 Baidu.com, Inc. All Rights Reserved
 * 
 **************************************************************************/
 
 
 
/**
 * @todo 首页
 * @package controllers 
 * @file home.php
 * @author lihongliang01@baidu.com
 * @date 2014年12月7日 下午9:26:04
 * 
 *  
 **/

class Home extends MY_APP_Controller {
	
	public function index($catId=false) {
		$this->loadModel('Post_model', 'article');
		//头部置顶文章
		$topArticles = $this->article->findByField(array('is_top'=>1), 'sorts desc', 3);
		//左侧分类
		$this->loadModel('Category_model', 'category');
		$categories = $this->category->findByField(array('type'=>'article'), 'sorts desc');
		//热门文章
		$hotArticles = $this->article->findByField(array('is_hot'=>1), 'sorts desc', 5);
		//精彩评论
		$this->loadModel('Comments_model', 'comment');
		$comments = $this->comment->find(array('order'=>array('likes'=>'desc'),'limit'=>5));
		//中间的分页显示文章
		$map = array(
			'where'=>array('is_show' => 1),
			'order' => array('sorts'=>'desc','id'=>'desc'),
		);
		if ($catId) {
			$map['where']['category_id'] = (int)$catId;
		}
		$this->assign['result'] = $this->getPager($this->article,$map);
		$this->assign['top'] = $topArticles;
		$this->assign['categories'] =  $categories;
		$this->assign['hot'] = $hotArticles;
		$this->assign['comments'] = $comments;
		$this->display();
	}
}

/*End of file home.php*/
/*Location home.php */